package com.bwie.init;

import com.bwie.common.domain.Coupon;
import com.bwie.common.domain.request.CouponRequest;
import com.bwie.mapper.CouponMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @className: CouponInit
 * @Description: TODO
 * @version: v1.８.0
 * @author: 刘茂锴
 * @date: 2025/10/13 17:17
 */
@Component
public class CouponInit implements ApplicationRunner {
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private CouponMapper couponMapper;
    @Override
    public void run(ApplicationArguments args) throws Exception {
        //查询所有的优惠券
        List<Coupon> list = couponMapper.couponList(new CouponRequest());
        //将所有的优惠券添加到redis中
        redisTemplate.opsForValue().set("coupon:couponList",list);
    }
}
